package org.elip.teststatistics.client;

import org.elip.teststatistics.client.ui.MainView;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.CardLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Test_Statistics extends Viewport implements EntryPoint {

	private CardLayout _cardLayout;
	private MainView _testLogs;
	private LogsServiceAsync _logsService;
	private ProductServiceAsync _productService;
	private SuitesServiceAsync _suitesService;
	private TestsServiceAsync _testsService;
	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		
		RootPanel rootPanel = RootPanel.get();
		
		rootPanel.add(this);
		
		initMainView();
		
	}

	private void initMainView() {
		
		final int windowWidth = Window.getClientWidth();
		final int windowHeight = Window.getClientHeight();
		
		_logsService = (LogsServiceAsync) GWT.create(LogsService.class);
		_productService = (ProductServiceAsync) GWT.create(ProductService.class);
		_suitesService = (SuitesServiceAsync) GWT.create(SuitesService.class);
		_testsService = (TestsServiceAsync) GWT.create(TestsService.class);
		
		_testLogs = new MainView(this, _logsService, _productService, _suitesService, _testsService);
		
		_cardLayout = new CardLayout();
		setLayout(_cardLayout);
		
		add(_testLogs);
		
		setSize(windowWidth, windowHeight);
		
		_cardLayout.setActiveItem(_testLogs);
	}
	
	public void showView(LayoutContainer view) {
		removeAll();
		add(view);
		_cardLayout.setActiveItem(view);
	}
}
